import {get,post,del,put} from "@/utils/request";
import {Concert} from "@/utils/BeanConvert.ts"

function deleteSystemById(id){
    return new Promise((resolve, reject) => {
        del(`/system/info/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function updateSystemById(id,system){
    return new Promise((resolve, reject) => {
        put(`/system/info/${id}`,system).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function createSystem(system){
    return new Promise((resolve, reject) => {
        post(`/system/info`,system).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function selectSystemById(id){
    return new Promise((resolve, reject) => {
        get(`/system/info/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function getSystemByCode(code){
    return new Promise((resolve, reject) => {
        get(`/system/infoByCode/`+ code,null).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function systemPage(params={}){
    return new Promise((resolve, reject) => {
        get(`/system/page`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function getParamSystemList(){
    return new Promise((resolve, reject) => {
        get(`/system/params`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function needCheckCode(principal){
    return new Promise((resolve, reject) => {
        get(`/login/captcha/need`, Concert.getParams({principal:principal})).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function getCheckCode(width,height,principal){
    return new Promise((resolve, reject) => {
        get(`/login/captcha`, Concert.getParams({width:width,height:height,principal:principal})).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function toLogin(loginName,password,code){
    return new Promise((resolve, reject) => {
        post(`/login/password`,{loginName:loginName,loginPassword:password,code:code}).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function selectLoginById(id,moduleName){
    return new Promise((resolve, reject) => {
        get(`/login/info/${id}`,Concert.getParams(moduleName?{moduleName:moduleName}:{})).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}


function currentLogin(moduleName){
    return new Promise((resolve, reject) => {
        get(`/login/info`,Concert.getParams(moduleName?{moduleName:moduleName}:{})).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function allowUseLoginName(loginName,id){
    return new Promise((resolve, reject) => {
        get(`/login/allow/${loginName}`,{matchLoginId:id}).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function deleteLoginById(id){
    return new Promise((resolve, reject) => {
        del(`/login/info/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function updateLoginById(id,login){
    return new Promise((resolve, reject) => {
        put(`/login/info/${id}`,login).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function updateCurrentLoginPassword(oldPassword,newPassword){
    return new Promise((resolve, reject) => {
        put(`/login/password`, {oldPassword:oldPassword,newPassword:newPassword}).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function updateSubLoginPassword(loginId,password){
    return new Promise((resolve, reject) => {
        put(`/login/password/${loginId}`, {password:password}).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function createLogin(login){
    return new Promise((resolve, reject) => {
        post(`/login/info`,login).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function loginPage(params={}){
    return new Promise((resolve, reject) => {
        get(`/login/page`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function loginRoleRelationPage(bindingStatus,roleId,params={}){
    return new Promise((resolve, reject) => {
        get(`/login/role/${bindingStatus}/${roleId}`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function roleBindingLoginInvoke(bindingStatus,roleId,loginId){
    return new Promise((resolve, reject) => {
        post(`/login/role/${bindingStatus}/${loginId}/${roleId}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function searchTreeMenus(systemCode,signboard){
    return new Promise((resolve, reject) => {
        get(`/menu/tree/${systemCode}/${signboard}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function createRole(role){
    return new Promise((resolve, reject) => {
        post(`/role/info`,role).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function selectRoleById(systemCode,id){
    return new Promise((resolve, reject) => {
        get(`/role/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function selectRoleByCode(systemCode,code){
    return new Promise((resolve, reject) => {
        get(`/role/infoByCode/${systemCode}/${code}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function deleteRoleById(systemCode,id){
    return new Promise((resolve, reject) => {
        del(`/role/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function updateRoleById(systemCode,id,menu){
    return new Promise((resolve, reject) => {
        put(`/role/info/${systemCode}/${id}`,menu).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function rolePage(params={}){
    return new Promise((resolve, reject) => {
        get(`/role/page`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function roleMenuRelationPage(bindingStatus,menuId,params={}){
    return new Promise((resolve, reject) => {
        get(`/role/menu/${bindingStatus}/${menuId}`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function roleRouterRelationPage(bindingStatus,routerId,params={}){
    return new Promise((resolve, reject) => {
        get(`/role/router/${bindingStatus}/${routerId}`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function rolePermissionRelationPage(bindingStatus,permissionId,params={}){
    return new Promise((resolve, reject) => {
        get(`/role/permission/${bindingStatus}/${permissionId}`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function roleLoginRelationPage(bindingStatus,menuId,params={}){
    return new Promise((resolve, reject) => {
        get(`/role/login/${bindingStatus}/${menuId}`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}


function menuBindingInvoke(bindingStatus,roleId,menuId){
    return new Promise((resolve, reject) => {
        post(`/role/menu/${bindingStatus}/${roleId}/${menuId}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function permissionBindingInvoke(bindingStatus,roleId,permissionId){
    return new Promise((resolve, reject) => {
        post(`/role/permission/${bindingStatus}/${roleId}/${permissionId}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function loginBindingInvoke(bindingStatus,roleId,permissionId){
    return new Promise((resolve, reject) => {
        post(`/role/login/${bindingStatus}/${roleId}/${permissionId}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function selectPermissionById(systemCode,id){
    return new Promise((resolve, reject) => {
        get(`/permission/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function selectPermissionByCode(systemCode,code){
    return new Promise((resolve, reject) => {
        get(`/permission/infoByCode/${systemCode}/${code}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function updatePermissionById(systemCode,id,menu){
    return new Promise((resolve, reject) => {
        put(`/permission/info/${systemCode}/${id}`,menu).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function deletePermissionById(systemCode,id){
    return new Promise((resolve, reject) => {
        del(`/permission/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function createPermission(permission){
    return new Promise((resolve, reject) => {
        post(`/permission/info`,permission).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function permissionPage(params={}){
    return new Promise((resolve, reject) => {
        get(`/permission/page`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function roleBindingPermissionInvoke(bindingStatus,roleId,permissionId){
    return new Promise((resolve, reject) => {
        post(`/permission/role/${bindingStatus}/${permissionId}/${roleId}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function menuSignboard(systemCode){
    return new Promise((resolve, reject) => {
        get(`/menu/signboard/${systemCode}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function selectMenuById(systemCode,id){
    return new Promise((resolve, reject) => {
        get(`/menu/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function createMenu(menu){
    return new Promise((resolve, reject) => {
        post(`/menu/info`,menu).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function updateMenuById(systemCode,id,menu){
    return new Promise((resolve, reject) => {
        put(`/menu/info/${systemCode}/${id}`,menu).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function menuPage(params={}){
    return new Promise((resolve, reject) => {
        get(`/menu/page`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function menuRoleRelationPage(bindingStatus,roleId,params={}){
    return new Promise((resolve, reject) => {
        get(`/menu/role/${bindingStatus}/${roleId}`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function deleteMenuById(systemCode,id){
    return new Promise((resolve, reject) => {
        del(`/menu/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function permissionRoleRelationPage(bindingStatus,roleId,params={}){
    return new Promise((resolve, reject) => {
        get(`/permission/role/${bindingStatus}/${roleId}`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function permissionRouterRelationPage(bindingStatus,relationId,params={}){
    return new Promise((resolve, reject) => {
        get(`/permission/router/${bindingStatus}/${relationId}`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function routerPage(params={}){
    return new Promise((resolve, reject) => {
        get(`/router/page`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function selectRouterById(systemCode,id){
    return new Promise((resolve, reject) => {
        get(`/router/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function createRouter(obj){
    return new Promise((resolve, reject) => {
        post(`/router/info`,obj).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function updateRouterById(systemCode,id,obj){
    return new Promise((resolve, reject) => {
        put(`/router/info/${systemCode}/${id}`,obj).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function deleteRouterById(systemCode,id){
    return new Promise((resolve, reject) => {
        del(`/router/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function allowUseRouter(systemCode,routerUrl,requestType,matchRouterId){
    return new Promise((resolve, reject) => {
        get(`/router/allow/${systemCode}`,Concert.getParams({routerUrl:routerUrl,requestType:requestType,matchRouterId:matchRouterId})).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function routerBindingInvoke(bindingStatus,routerId,relationId,isRole){
    return new Promise((resolve, reject) => {
        post(`/router/relation/${bindingStatus}/${routerId}/${relationId}/${isRole}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function searchModuleNames(systemCode){
    return new Promise((resolve, reject) => {
        get(`/form/modules/${systemCode}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function moduleTypes(){
    return new Promise((resolve, reject) => {
        get(`/form/moduleTypes`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function modulePlugs(systemCode,moduleName,fieldType,formId){
    return new Promise((resolve, reject) => {
        get(`/form/plugs/${systemCode}/${moduleName}/${fieldType}`,Concert.getParams({formId:formId})).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function createForm(form){
    return new Promise((resolve, reject) => {
        post(`/form/info`,form).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function updateFormById(systemCode,id,form){
    return new Promise((resolve, reject) => {
        put(`/form/info/${systemCode}/${id}`,form).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function deleteFormById(systemCode,id){
    return new Promise((resolve, reject) => {
        del(`/form/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function selectFormById(systemCode,id){
    return new Promise((resolve, reject) => {
        get(`/form/info/${systemCode}/${id}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function formPage(params={}){
    return new Promise((resolve, reject) => {
        get(`/form/page`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function searchFields(systemCode,moduleName,params){
    return new Promise((resolve, reject) => {
        get(`/form/fields/${systemCode}/${moduleName}`,Concert.getParams(params)).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function previewValue(systemCode,moduleName,plugName){
    return new Promise((resolve, reject) => {
        get(`/form/preview/${systemCode}/${moduleName}/${plugName}`).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}



export {getSystemByCode,systemPage,getParamSystemList,needCheckCode,getCheckCode,toLogin,loginPage,deleteLoginById,updateLoginById,
    createLogin, allowUseLoginName, selectLoginById,loginRoleRelationPage,roleBindingLoginInvoke,searchTreeMenus,roleLoginRelationPage,
    deleteRoleById,rolePage,createRole,selectRoleById,selectRoleByCode,updateRoleById,roleMenuRelationPage,rolePermissionRelationPage,
    menuBindingInvoke, permissionBindingInvoke,loginBindingInvoke,permissionPage,menuSignboard,menuPage,menuRoleRelationPage,
    selectMenuById,createMenu, updateMenuById,deleteMenuById,permissionRoleRelationPage,deleteSystemById,selectSystemById,
    updateSystemById,createSystem, selectPermissionById,selectPermissionByCode,updatePermissionById,createPermission,
    deletePermissionById,roleBindingPermissionInvoke,routerPage,selectRouterById,deleteRouterById,allowUseRouter,createRouter,updateRouterById,
    permissionRouterRelationPage,roleRouterRelationPage,routerBindingInvoke,searchModuleNames,moduleTypes,modulePlugs,deleteFormById,
    createForm,updateFormById,selectFormById,formPage,searchFields,previewValue,currentLogin,updateCurrentLoginPassword,updateSubLoginPassword}